import 'package:flutter/material.dart';
import 'package:flutter_native_map/flutter_native_map.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  var circle;
  @override
  void initState() {
    super.initState();
    FlutterNativeMap.stream.listen((onData) {
      print("插件返回：${onData}");
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: SafeArea(
            child: Scaffold(
                body: Column(children: [
      const Expanded(child: AndroidView(viewType: 'mapNativeView')),
      Expanded(
        child: Padding(
          padding: const EdgeInsets.all(8.0),
          child: Wrap(
            children: [
              ElevatedButton(
                  onPressed: () async {
                    print(await FlutterNativeMap.checkPermission());
                  },
                  child: const Text("检查权限")),
              ElevatedButton(
                  onPressed: () async {
                    await FlutterNativeMap.requestPermission();
                  },
                  child: const Text("请求权限")),
              ElevatedButton(
                  onPressed: () async {
                    await FlutterNativeMap.moveCameraTo(30.635261, 104.096488);
                  },
                  child: const Text("移动相机")),
              ElevatedButton(
                  onPressed: () async {
                    circle = await FlutterNativeMap.drawCircle(
                        latitude: 30.635261,
                        longitude: 104.096488,
                        radius: 500,
                        fillColor: Colors.red.withAlpha(100),
                        strokeColor: Colors.blue.withAlpha(100),
                        strokeWidth: 10);
                  },
                  child: const Text("画圆圈")),
              ElevatedButton(
                  onPressed: () async {
                    await FlutterNativeMap.removeCircle(circle);
                  },
                  child: const Text("取消画圆圈")),
              ElevatedButton(
                  onPressed: () async {
                    print(await FlutterNativeMap.getLocation());
                  },
                  child: const Text("获取定位")),
              ElevatedButton(
                  onPressed: () async {
                    print(await FlutterNativeMap.isGpsOpen());
                  },
                  child: const Text("定位功能是否开启")),
            ],
          ),
        ),
      )
    ]))));
  }
}
